#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <graphics (2).h>
#include <ege.h>
#include <stdlib.h>
#include <Windows.h>
#include <math.h>
#include <algorithm>

struct Attitude {
	double side_wigth;
	double side_lenth;
	float edge;
	double x;
	double y;
} attitude = { 1000, 1000, 700, 50, 50 };

static double cl_wigth = attitude.side_wigth;				// 定义画布大小
static double cl_lenth = attitude.side_lenth;
static float edge = attitude.edge;			// 定义图形大小
static double x = attitude.x;				// 图形左上角x轴坐标
static double y = attitude.y;				// 图形左上角y轴坐标
static float angle = 0;				// 转动角度
static float pitch = 0;				// 俯仰角度
static float antagonistic1 = 0.5;		// 改变上下
static float antagonistic2 = edge / 700.0;

void draw_attitude(double cl_witgh, double cl_lenth, double X, double Y);			// 整体绘制
void draw_Layer1(float edge, float x, float y);				// 最下层图层
void draw_Layer2(float edge, float x, float y);				// 中间图层
void draw_Layer3(float edge, float x, float y);				// 最上层图层
void Outline_Frame(float edge, float x, float y);			// 外框的绘制
void Dashboard_Ring(float edge, float x, float y);			// 内框的绘制
void Outer_Ring(float edge, float x, float y);				// 黄色指示器
void Inside_shade(float edge, float x, float y);			// 内侧阴影
void Mid_whiteline(float edge, float x, float y);			// 中间白线
void Marking(float edge, float x, float y);					// 外侧天地环
void Attitude(float edge, float x, float y);				// 表内测姿态指示线
void Shield(float edge, float x, float y);					// 表内侧黑色盖板
void Frames(float edge, float x, float y);					// 最外侧框绘制
void Min_line(float edge, float x, float y);				// 中间角度标识线
void Mid_char(float edge, float x, float y);				// 中间标识文字
void draweline(float edge, float x, float y);				// 中间椭圆线
void screw(float edge, float x, float y);					// 绘制螺钉
void Cover(float edge, float x, float y);					// 覆盖颜色
void character(float edge, float x, float y);				// 打印字符
void Revolve_line(float x1, float y1, float x2, float y2, float cx, float cy);				// 绘制旋转的线
void draw_screw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);				// 绘制螺钉函数
void rotatePoint(float x, float y, float centerX, float centerY, float angle, float& x_new, float& y_new);				// 定义旋转函数

int main(void)
{

	for (int i = 0; i < 10; i++) {
		initgraph(cl_wigth, cl_lenth, INIT_RENDERMANUAL);
		setbkcolor(EGEARGB(0XFF, 0x14, 0x14, 0x14));
		draw_attitude(450, 700, 50, 50);  // 这里改位置和大小，前两个必须一样，后两个为左上角坐标
	}

	return 0;
}

// 整体绘制
void draw_attitude(double len_wigth, double len_lenth, double x, double y)
{

	// 抗锯齿
	ege_enable_aa(true);
	ege_setalpha(255);
	for (; is_run(); delay_fps(60)) {
		cleardevice();

		int edge = len_wigth;
		draw_Layer1(edge, x, y);
		draw_Layer2(edge, x, y);
		draw_Layer3(edge, x, y);
		character(edge, x, y);
		Frames(edge, x, y);

		// 画布变白
		setfillcolor(EGERGB(255, 255, 255, 255));
		floodfillsurface(x - (edge / 60.0) - 1, y - (edge / 60.0) - 1, EGERGB(20, 20, 20, 255));
		angle += 1 * antagonistic1;
		pitch += 1 * antagonistic2;
		if (angle > 360.0 || angle < -360.0) {
			antagonistic1 *= -1;
		}
		int tem = edge;
		if (tem >= 1000) {
			tem = 1000;
		}
		if (tem <= 300) {
			tem = 300;
		}
		if (pitch > tem / 6.0 || pitch < -tem / 6.0) {
			antagonistic2 *= -1;
		}
		xyprintf(0, 0, "FPS:%.3f", getfps());			//显示帧率
	}
}

// 最下层图层 (NO.1)
void draw_Layer1(float edge, float x, float y)
{
	// 第一个图层
	setbkcolor(EGEARGB(0XFF, 0x14, 0x14, 0x14));
	setbkmode(OPAQUE);

	Mid_whiteline(edge, x, y);
	Attitude(edge, x, y);
	draweline(edge, x, y);
	Min_line(edge, x, y);
	//Mid_char(edge, x, y);
	//screw(edge, x, y);
}

// 中间图层 (NO.2)
void draw_Layer2(float edge, float x, float y)
{
	// 第二个图层
	setbkcolor(EGEARGB(0XFF, 0x14, 0x14, 0x14));
	setbkmode(OPAQUE);

	Inside_shade(edge, x, y);
	Outer_Ring(edge, x, y);
	Marking(edge, x, y);
	Shield(edge, x, y);

}

// 最上层图层 (NO.3)
void draw_Layer3(float edge, float x, float y)
{
	// 第三个图层
	setbkcolor(EGEARGB(0XFF, 0x14, 0x14, 0x14));
	setbkmode(OPAQUE);
	ege_setalpha(255);

	Outline_Frame(edge, x, y);
	Dashboard_Ring(edge, x, y);
	Cover(edge, x, y);
}

// 外框的绘制
void Outline_Frame(float edge, float x, float y)
{
	setlinewidth(1);

	for (int i = 0; i < 10; i++) {
		ege_enable_aa(true);
		// 外框：弧线
		for (int i = 0; i < (int)(edge / 53.846); i++) {
			setcolor(EGERGB(75 + 10 * i, 75 + 10 * i, 75 + 10 * i, 255));
			ege_arc(-(edge / 14 * 3) + x, y + i, (edge / 7 * 10), (edge / 7 * 10), 240, 60);
			ege_arc(x + i, -(edge / 14 * 3) + y, (edge / 7 * 10), (edge / 7 * 10), 150, 60);
			ege_arc(-(edge / 14 * 3) + x, -(edge / 14 * 6) + y - i, (edge / 7 * 10), (edge / 7 * 10), 60, 60);
			ege_arc(-(edge / 14 * 6) + x - i, -(edge / 14 * 3) + y, (edge / 7 * 10), (edge / 7 * 10), 330, 60);
		}
		// 外框：直线
		for (int i = 0; i < (int)(edge / 53.846); i++) {
			setcolor(EGERGB(75 + 10 * i, 75 + 10 * i, 75 + 10 * i, 255));
			ege_line((edge / 7.000) + x, (edge / 10.447761194) + y + i, (edge / 10.447761194) + x + i, (edge / 7.000) + y);
			ege_line((edge / 1.166666667) + x, (edge / 10.447761194) + y + i, (edge / 1.10584518) + x - i, (edge / 7.000) + y);
			ege_line((edge / 7.000) + x, (edge / 1.10584518) + y - i, (edge / 10.447761194) + x + i, (edge / 1.166666667) + y);
			ege_line((edge / 1.10584518) + x - i, (edge / 1.166666667) + y, (edge / 1.166666667) + x, (edge / 1.10584518) + y - i);
		}
	}
}

// 内框的绘制
void Dashboard_Ring(float edge, float x, float y)
{
	setlinewidth(1);

	// 仪表框：圆弧
	for (int i = 0; i < (int)(edge / 7.0 / 14.0); i++) {
		setcolor(EGERGB(10 + 20 * i, 10 + 20 * i, 10 + 20 * i, 255));
		ege_arc((edge / 10.76923) + x + ((float)i * edge / 700.0), (edge / 9.333333) + y + ((float)i * edge / 700.0), (edge / 1.232) - ((edge / 350.0) * ((float)i * edge / 700.0)), (edge / 1.27) - ((edge / 350.0) * ((float)i * edge / 700.0)), 149, 242);
	}
	// 仪表框：直线
	for (int i = 0; i < (int)(edge / 7.0 / 14.0); i++) {
		setcolor(EGERGB(10 + 20 * i, 10 + 20 * i, 10 + 20 * i, 255));
		ege_line((edge / 6.66667) + x + i, (edge / 1.42857) + y, (edge / 2.6415) + x, (edge / 1.20689655) - i + y);
		ege_line((edge / 1.609) + x, (edge / 1.20689655) + y - i, (edge / 1.17647) + x - i, (edge / 1.42857) + y);
		ege_line((edge / 2.6415) + x, (edge / 1.20689655) + y - i, (edge / 1.609) + x, (edge / 1.20689655) + y - i);
	}
}

// 内侧阴影
void Inside_shade(float edge, float x, float y)
{
	setlinewidth(edge / 700.0 * 30.0);
	setcolor(EGEARGB(0x70, 0x10, 0x10, 0x10));
	ege_arc(edge / 5.8333333 + x, edge / 5.3846153846 + y, edge - (2.0 * edge / 5.8333333), edge - (2.0 * edge / 5.3846153846), 0, 360);
	setcolor(EGEARGB(0x50, 0x10, 0x10, 0x10));
	ege_arc(edge / 5.7377049 + x, edge / 5.303030303 + y, edge - (2.0  * edge / 5.7377049), edge - (2.0 * edge / 5.303030303), 0, 360);
	setcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
	ege_arc(edge / 5.6 + x, edge / 5.185185185 + y, edge - (2.0 * edge / 5.6), edge - (2.0 * edge / 5.185185185), 0, 360);
	setcolor(EGEARGB(0x30, 0x10, 0x10, 0x10));
	ege_arc(edge / 5.46875 + x, edge / 5.072463768 + y, edge - (2.0 * edge / 5.46875), edge - (2.0 * edge / 5.072463768), 0, 360);
	setcolor(EGEARGB(0x30, 0x10, 0x10, 0x10));
	ege_arc(edge / 5.3846153846 + x, edge / 5.0 + y, edge - (2.0 * edge / 5.3846153846), edge - (2.0 * edge / 5.0), 0, 360);
}

// 黄色指示器
void Marking(float edge, float x, float y)
{
	// 黄色固定指示器
	for (int i = 1; i <= 2; i++) {				// 绘制两次，使完全覆盖
		// 中间连接线
		setlinewidth(edge / 70.0);
		setcolor(EGERGB(70, 65, 45, 255));
		ege_line(edge / 2.05278592375 + x, edge / 1.772151898734 + y, edge / 1.949860724 + x, edge / 1.772151898734 + y);
		setlinewidth(edge / 700.0 * 5.0);
		setcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
		ege_line(edge / 2.05278592375 + x, edge / 1.79487179487 + y, edge / 1.949860724 + x, edge / 1.79487179487 + y);
		ege_line(edge / 2.05278592375 + x, edge / 1.78117048346 + y, edge / 1.949860724 + x, edge / 1.78117048346 + y);
		setcolor(EGEARGB(0x50, 0xff, 0xff, 0xff));
		ege_line(edge / 2.05278592375 + x, edge / 1.75 + y, edge / 1.949860724 + x, edge / 1.75 + y);

		// 支撑部分
		setlinewidth(edge / 700.0 * 18.0);
		setcolor(EGERGB(70, 65, 45, 255));
		ege_line(edge / 2.0 + x, edge / 1.75 + y, edge / 2.0 + x, edge / 1.47368421 + y);
		setlinewidth(edge / 70.0);
		setcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
		ege_line(edge / 2.0289855 + x, edge / 1.75 + y, edge / 2.0289855 + x, edge / 1.47368421 + y);
		ege_line(edge / 1.9718309859 + x, edge / 1.75 + y, edge / 1.9718309859 + x, edge / 1.47368421 + y);
		setlinewidth(edge / 35.0);
		setcolor(EGEARGB(0x20, 0x10, 0x10, 0x10));
		ege_line(edge / 1.9718309859 + x, edge / 1.75 + y, edge / 1.9718309859 + x, edge / 1.47368421 + y);
		setlinewidth(edge / 140.0);
		setcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
		ege_line(edge / 2.04081632653 + x, edge / 1.75 + y, edge / 2.04081632653 + x, edge / 1.47368421 + y);
		ege_line(edge / 1.9607843137 + x, edge / 1.75 + y, edge / 1.9607843137 + x, edge / 1.47368421 + y);
		setlinewidth(edge / 700.0 * 9.0);
		setcolor(EGEARGB(0x50, 0x46, 0x46, 0x2d));
		ege_line(edge / 2.0 + x, edge / 1.75 + y, edge / 2.0 + x, edge / 1.47368421 + y);

		// 左侧竖线
		setlinewidth(edge / 100.0);
		setcolor(EGEARGB(0x60, 0x10, 0x10, 0x10));
		ege_line(edge / 3.41463414634 + x, edge / 2.834008097 + y, edge / 3.41463414634 + x, edge / 1.5317286652 + y);
		setcolor(EGEARGB(0x20, 0x10, 0x10, 0x10));
		ege_line(edge / 3.3333333333 + x, edge / 2.8112449799 + y, edge / 3.3333333333 + x, edge / 1.52173913 + y);
		setcolor(EGERGB(140, 95, 60, 255));
		ege_line(edge / 3.5 + x, edge / 2.857142857 + y, edge / 3.5 + x, edge / 1.53846153846 + y);

		// 三叉中间的
		setfillcolor(EGERGB(70, 65, 45, 255));
		ege_fillrect(edge / 2.0289855 + x, edge / 1.97183 + y, edge / 70.0, edge / 70.0 * 3.0);
		setfillcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
		ege_point point3[] = { {edge / 2.94117647 + x, edge / 1.9943019943 + y}, {edge / 2.258064516 + x, edge / 1.9943019943 + y}, {edge / 2.2364217252396 + x, edge / 1.949860724 + y}, {edge / 2.941176470588 + x, edge / 1.949860724 + y} };
		ege_fillpoly(4, point3);
		ege_point point4[] = { {edge / 1.4957264957 + x, edge / 1.9943019943 + y}, {edge / 1.78117048346 + x, edge / 1.9943019943 + y}, {edge / 1.79487179487 + x, edge / 1.949860724 + y}, {edge / 1.4957264957 + x, edge / 1.949860724 + y} };
		ege_fillpoly(4, point4);

		// 黄色圆
		setfillcolor(EGERGB(140, 95, 60, 255));
		ege_fillellipse(edge / 2.0 - edge / 90.0 + x, edge / 2.0 - edge / 90.0 + y, edge / 45.0, edge / 45.0);

		// 棕色架子：环线
		setlinewidth(edge / 70.0);
		setcolor(EGEARGB(0x30, 0x10, 0x10, 0x10));
		ege_arc(edge / 2.258064516 + x, edge / 2.258064516 + y, edge / 8.0, edge / 8.75, 3, 174);
		setcolor(EGERGB(70, 65, 45, 255));
		ege_arc(edge / 2.0 - edge / 16.0 + x, edge / 2.2950819672 + y, edge / 8.0, edge / 8.75, 3, 174);

		// 与圆相平的线
		setfillcolor(EGERGB(140, 95, 60, 255));
		ege_point point1[] = { {edge / 2.978723404 + x, edge / 2.023121387 + y}, {edge / 2.258064516129 + x, edge / 2.023121387 + y}, {edge / 2.236421725 + x, edge / 1.9774011299435 + y}, {edge / 2.978723404 + x, edge / 1.9774011299435 + y} };
		ege_fillpoly(4, point1);
		ege_point point2[] = { {edge / 1.505376344 + x, edge / 2.023121387 + y}, {edge / 1.79487179487 + x, edge / 2.023121387 + y}, {edge / 1.8087855297 + x, edge / 1.9774011299435 + y}, {edge / 1.505376344 + x, edge / 1.9774011299435 + y} };
		ege_fillpoly(4, point2);
	}
}

// 外侧天地环
void Outer_Ring(float edge, float x, float y)
{
	setlinewidth(edge / 700.0 * 55.0);

	// 蓝色半环
	setcolor(EGEARGB(0xFF, 0x1e, 0x28, 0x46));
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)180 + angle, 180);

	// 黄色半环
	setcolor(EGERGB(100, 80, 45, 255));
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle, 180);

	// 刻度
	setcolor(EGERGB(170, 180, 200, 255));
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle - 1.0, 2.0);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 179.0, 2.0);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 209.5, 1);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 329.5, 1);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 269, 2);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 239, 2);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 299, 2);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 249.5, 1);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 259.5, 1);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 279.5, 1);
	ege_arc(edge / 7.0 + x, edge / 6.3636363636 + y, edge - (2.0 * edge / 7.0), edge - (2.0 * edge / 6.3636363636), (float)0 + angle + 289.5, 1);

	// 阴影
	setlinewidth(edge / 35.0);
	setcolor(EGEARGB(0x70, 0x10, 0x10, 0x10));
	ege_arc(edge / 10.0 + x, edge / 9.33333333 + y, edge - (2.0 * edge / 10.0), edge - (2.0 * edge / 9.33333333), 0, 360);
	setcolor(EGEARGB(0x60, 0x10, 0x10, 0x10));
	ege_arc(edge / 9.33333333 + x, edge / 8.75 + y, edge - (2.0 * edge / 9.33333333), edge - (2.0 * edge / 8.75), 0, 360);
	setcolor(EGEARGB(0x50, 0x10, 0x10, 0x10));
	ege_arc(edge / 8.75 + x, edge / 8.235294117647 + y, edge -(2.0 * edge / 8.75), edge - (2.0 * edge / 8.235294117647), 0, 360);
	setcolor(EGEARGB(0x30, 0x10, 0x10, 0x10)); 
	ege_arc(edge / 8.75 + x, edge / 8.235294117647 + y, edge - (2.0 * edge / 8.75), edge - (2.0 * edge / 8.235294117647), 0, 360);

	// 白色三角形
	setfillcolor(EGEARGB(0x40, 0x10, 0x10, 0x10));
	ege_point points[] = { {edge / 2.0 + x, edge / 5.072463768 + y}, {edge / 2.153846153846 + x, edge / 3.93258426966 + y}, {edge / 1.86666666 + x, edge / 3.93258426966 + y} };
	ege_fillpoly(3, points);
	setfillcolor(EGERGB(150, 160, 180, 255));
	ege_point points1[] = { {edge / 2.0 + x, edge / 5.3846153846 + y}, {edge / 2.153846153846 + x, edge / 4.1176470588 + y}, {edge / 1.86666666 + x, edge / 4.1176470588 + y} };
	ege_fillpoly(3, points1);
}

// 表内侧黑色盖板
void Shield(float edge, float x, float y)
{
	// 黑色盖板	;
	setlinewidth(edge / 7.0);
	setcolor(EGEARGB(0xFF, 0x00, 0x00, 0x00));
	ege_arc(x, edge / 1.346153846 + y, edge, (edge / 7 * 4), 215, 110);

	setlinewidth(edge / 350.0 * 1.5);
	setcolor(EGERGB(70, 70, 70, 255));
	ege_arc(x, edge / 1.467505241 + y, edge, (edge / 7 * 4), 220, 100);
	
	setlinewidth(edge / 700.0 * 3.0);
	setcolor(EGERGB(140, 140, 140, 255));
	ege_arc(x, edge / 1.4893617 + y, edge, (edge / 7 * 4), 215, 110);
	
	setlinewidth(edge / 70.0 * 3.0);	
	setcolor(EGEARGB(0xFF, 0x00, 0x00, 0x00));
	ege_line((edge / 2.64153) + x, edge / 1.20689655 + y, (edge / 1.6091954) + x, (edge / 1.2048192771) + y);
}

// 中间白线
void Mid_whiteline(float edge, float x, float y)
{
	// 设置线段宽度
	setlinewidth(edge / 70.0);
	setcolor(EGERGB(170, 180, 200, 255));

	// 在外围绘制圆圈，形成封闭图形
	ege_arc(((edge / 9.722222) + x) + ((float)(edge / (edge / 45.0)) * edge / 700.0), ((edge / 8.5365853658) + y) + ((float)(edge / (edge / 45.0)) * edge / 700.0), (556.0 * edge / 700.0) - 2.0 * (edge / 700 * (float)(edge / (edge / 45.0))), (536.0 * edge / 700.0) - 2.0 * (edge / 700.0 * (float)(edge / (edge / 45.0))), (float)0, 360);

	float x1 = edge / 6.08695652 + x, y1 = edge / 2.0 + y;
	float x2 = edge / 1.19658119658 + x, y2 = edge / 2.0 + y;
	float centerX = edge / 2.0 + x, centerY = edge / 2.0 + y;
	float an = angle * 3.1414926 / 180.0;
	float lengthScale = 0.97; // 长度缩放比例

	float x1_new, y1_new, x2_new, y2_new;
	rotatePoint(x1, y1 + pitch, centerX, centerY, an, x1_new, y1_new);
	rotatePoint(x2, y2 + pitch, centerX, centerY, an, x2_new, y2_new);
	float dx = x2_new - x1_new;
	float dy = y2_new - y1_new;
	float length = sqrt(dx * dx + dy * dy);

	// 使线段的长度可变
	float dx_new = dx * lengthScale;
	float dy_new = dy * lengthScale;
	float x1_new_adjusted = x1_new + (dx - dx_new) / 2;
	float y1_new_adjusted = y1_new + (dy - dy_new) / 2;
	float x2_new_adjusted = x2_new - (dx - dx_new) / 2;
	float y2_new_adjusted = y2_new - (dy - dy_new) / 2;
	ege_line(x1_new_adjusted, y1_new_adjusted, x2_new_adjusted, y2_new_adjusted);
}

// 表内测姿态指示线
void Min_line(float edge, float x, float y)
{
	// 画出中间长短不一的线
	setlinewidth(edge / 700.0 * 5.0);
	Revolve_line(edge / 2.1212121212 + x, edge / 2.9787234 + y, edge / 1.89189189 + x, edge / 2.9787234 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.1212121212 + x, edge / 1.505376344 + y, edge / 1.89189189 + x, edge / 1.505376344 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.5 + x, edge / 2.745098 + y, edge / 1.66666666 + x, edge / 2.745098 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.5 + x, edge / 1.5730337 + y, edge / 1.66666666 + x, edge / 1.5730337 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.1212121212 + x, edge / 2.5 + y, edge / 1.89189189 + x, edge / 2.5 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.1212121212 + x, edge / 1.66666666 + y, edge / 1.89189189 + x, edge / 1.66666666 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.29508 + x, edge / 2.29508 + y, edge / 1.77215 + x, edge / 2.29508 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.29508 + x, edge / 1.77215 + y, edge / 1.77215 + x, edge / 1.77215 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.1212121212 + x, edge / 2.153846 + y, edge / 1.89189189 + x, edge / 2.153846 + y, edge / 2.0 + x, edge / 2.0 + y);
	Revolve_line(edge / 2.1212121212 + x, edge / 1.8666666666 + y, edge / 1.89189189 + x, edge / 1.8666666666 + y, edge / 2.0 + x, edge / 2.0 + y);

	setbkmode(TRANSPARENT);
}

// 中间标识文字
void Mid_char(float edge, float x, float y)
{
	float centerX = edge / 2.0 + x, centerY = edge / 2.0 + y;
	float an = angle * 3.1414926 / 180.0;

	float x1 = 250 + x, y1 = 245 + y, x1_new, y1_new;
	float x2 = 425 + x, y2 = 245 + y, x2_new, y2_new;
	float x3 = 250 + x, y3 = 435 + y, x3_new, y3_new;
	float x4 = 425 + x, y4 = 435 + y, x4_new, y4_new;
	rotatePoint(x1, y1 + pitch, centerX, centerY, an, x1_new, y1_new);
	rotatePoint(x2, y2 + pitch, centerX, centerY, an, x2_new, y2_new);
	rotatePoint(x3, y3 + pitch, centerX, centerY, an, x3_new, y3_new);
	rotatePoint(x4, y4 + pitch, centerX, centerY, an, x4_new, y4_new);
	float x5 = 275 + x, y5 = 295 + y, x5_new, y5_new;
	float x6 = 400 + x, y6 = 295 + y, x6_new, y6_new;
	float x7 = 275 + x, y7 = 385 + y, x7_new, y7_new;
	float x8 = 400 + x, y8 = 385 + y, x8_new, y8_new;
	rotatePoint(x5, y5 + pitch, centerX, centerY, an, x5_new, y5_new);
	rotatePoint(x6, y6 + pitch, centerX, centerY, an, x6_new, y6_new);
	rotatePoint(x7, y7 + pitch, centerX, centerY, an, x7_new, y7_new);
	rotatePoint(x8, y8 + pitch, centerX, centerY, an, x8_new, y8_new);

	setcolor(EGERGB(170, 180, 200, 255));
	setfont((edge / 7 / 4), 10, "等线", angle * -10.00, angle * -10.00, 2000, false, false, false);

	LOGFONTA f;
	getfont(&f);
	f.lfQuality = ANTIALIASED_QUALITY;
	setfont(&f);

	setbkmode(EGERGB(20, 20, 20, 255));
	outtextxy((int)x1_new, (int)y1_new, "20");
	outtextxy((int)x2_new, (int)y2_new, "20");
	outtextxy((int)x3_new, (int)y3_new, "20");
	outtextxy((int)x4_new, (int)y4_new, "20");
	outtextxy((int)x5_new, (int)y5_new, "10");
	outtextxy((int)x6_new, (int)y6_new, "10");
	outtextxy((int)x7_new, (int)y7_new, "10");
	outtextxy((int)x8_new, (int)y8_new, "10");
}

// 内测姿态显示
void Attitude(float edge, float x, float y)
{
	// 指定位置，进行颜色填充
	float an = angle * 3.1414926 / 180.0;
	float centerX = edge / 2.0 + x, centerY = edge / 2.0 + y;

	float x1 = edge / 2.857142857 + x, y1 = edge / 2.153846 + y;
	float x2 = edge / 2.857142857 + x, y2 = edge / 1.86666666666 + y;

	float x1_new, y1_new, x2_new, y2_new;
	rotatePoint(x1, y1 + pitch, centerX, centerY, an, x1_new, y1_new);
	rotatePoint(x2, y2 + pitch, centerX, centerY, an, x2_new, y2_new);
	setfillcolor(EGERGB(50, 70, 110, 255));
	floodfillsurface(x1_new, y1_new, EGEARGB(0XFF, 0x14, 0x14, 0x14));
	setfillcolor(EGERGB(130, 105, 60, 255));
	floodfillsurface(x2_new, y2_new, EGEARGB(0XFF, 0x14, 0x14, 0x14));

	float x3 = edge / 1.53846 + x, y3 = edge / 2.153846 + y;
	float x4 = edge / 1.53846 + x, y4 = edge / 1.86666666666 + y;

	// 第二次填充，确保完全覆盖
	float x3_new, y3_new, x4_new, y4_new;
	rotatePoint(x3, y3 + pitch, centerX, centerY, an, x3_new, y3_new);
	rotatePoint(x4, y4 + pitch, centerX, centerY, an, x4_new, y4_new);
	setfillcolor(EGERGB(50, 70, 110, 255));
	floodfillsurface(x1_new, y1_new, EGEARGB(0XFF, 0x14, 0x14, 0x14));
	setfillcolor(EGERGB(130, 105, 60, 255));
	floodfillsurface(x2_new, y2_new, EGEARGB(0XFF, 0x14, 0x14, 0x14));
}

// 中间椭圆线
void draweline(float edge, float x, float y)
{
	float centerX = edge / 2.0 + x, centerY = edge / 2.0 + y;
	float an = angle * 3.1414926 / 180.0;

	setlinewidth(edge / 300.0);
	setcolor(EGEARGB(0x80, 0x78, 0x96, 0xd2));
	float x1 = edge / 5.83333333 + x, y1 = edge / 2.333333333 + y, x1_new, y1_new;
	float x2 = edge / 3.414634 + x, y2 = edge / 2.9787234 + y, x2_new, y2_new;
	float x3 = edge / 2.0 + x, y3 = edge / 3.5 + y, x3_new, y3_new;
	float x4 = edge / 1.414141414 + x, y4 = edge / 2.9787234 + y, x4_new, y4_new;
	float x5 = edge / 1.20689655 + x, y5 = edge / 2.333333333 + y, x5_new, y5_new;
	rotatePoint(x1, y1 + pitch, centerX, centerY, an, x1_new, y1_new);
	rotatePoint(x2, y2 + pitch, centerX, centerY, an, x2_new, y2_new);
	rotatePoint(x3, y3 + pitch, centerX, centerY, an, x3_new, y3_new);
	rotatePoint(x4, y4 + pitch, centerX, centerY, an, x4_new, y4_new);
	rotatePoint(x5, y5 + pitch, centerX, centerY, an, x5_new, y5_new);
	ege_point points_1[] = { {x1_new, y1_new}, {x2_new, y2_new}, {x3_new, y3_new}, {x4_new, y4_new}, {x5_new, y5_new} };
	ege_drawcurve(5, points_1);

	setlinewidth(edge / 200.0);
	setcolor(EGEARGB(0x80, 00, 00, 00));
	float x6 = edge / 7.368421 + x, y6 = edge / 1.866666666 + y, x6_new, y6_new;
	float x7 = edge / 3.414634 + x, y7 = edge / 1.505376344 + y, x7_new, y7_new;
	float x8 = edge / 2.0 + x, y8 = edge / 1.4 + y, x8_new, y8_new;
	float x9 = edge / 1.414141414 + x, y9 = edge / 1.505376344 + y, x9_new, y9_new;
	float x10 = edge / 1.157024793 + x, y10 = edge / 1.8666666666 + y, x10_new, y10_new;
	rotatePoint(x6, y6 + pitch, centerX, centerY, an, x6_new, y6_new);
	rotatePoint(x7, y7 + pitch, centerX, centerY, an, x7_new, y7_new);
	rotatePoint(x8, y8 + pitch, centerX, centerY, an, x8_new, y8_new);
	rotatePoint(x9, y9 + pitch, centerX, centerY, an, x9_new, y9_new);
	rotatePoint(x10, y10 + pitch, centerX, centerY, an, x10_new, y10_new);
	ege_point points_2[] = { {x6_new, y6_new}, {x7_new, y7_new}, {x8_new, y8_new}, {x9_new, y9_new}, {x10_new, y10_new} };
	ege_drawcurve(5, points_2);
}

// 绘制螺钉
void screw(float edge, float x, float y)
{
	float x1 = 130 + x, y1 = 330 + y, x5 = 570 + x, y5 = 330 + y;
	float x2 = 135 + x, y2 = 325 + y, x6 = 565 + x, y6 = 325 + y;
	float x3 = 140 + x, y3 = 330 + y, x7 = 560 + x, y7 = 330 + y;
	float x4 = 135 + x, y4 = 335 + y, x8 = 565 + x, y8 = 335 + y;
	float a1 = 130 + x, b1 = 370 + y, a5 = 570 + x, b5 = 370 + y;
	float a2 = 135 + x, b2 = 375 + y, a6 = 565 + x, b6 = 375 + y;
	float a3 = 140 + x, b3 = 370 + y, a7 = 560 + x, b7 = 370 + y;
	float a4 = 135 + x, b4 = 365 + y, a8 = 565 + x, b8 = 365 + y;

	draw_screw(x1, y1, x2, y2, x3, y3, x4, y4);
	draw_screw(x5, y5, x6, y6, x7, y7, x8, y8);
	draw_screw(a1, b1, a2, b2, a3, b3, a4, b4);
	draw_screw(a5, b5, a6, b6, a7, b7, a8, b8);
}

// 绘制螺钉函数
void draw_screw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
{
	setlinestyle(1);
	float centerX = edge / 2.0, centerY = edge / 2.0;
	float an = angle * 3.1414926 / 180.0;

	float x1_new, y1_new, x2_new, y2_new, x3_new, y3_new, x4_new, y4_new;

	setcolor(EGERGB(192, 192, 192, 255));
	rotatePoint(x1, y1 + pitch, centerX, centerY, an, x1_new, y1_new);
	rotatePoint(x2, y2 + pitch, centerX, centerY, an, x2_new, y2_new);
	rotatePoint(x3, y3 + pitch, centerX, centerY, an, x3_new, y3_new);
	rotatePoint(x4, y4 + pitch, centerX, centerY, an, x4_new, y4_new);
	ege_point points[] = { {x1_new, y1_new}, {x2_new, y2_new}, {x3_new, y3_new}, {x4_new, y4_new} };
	ege_drawcurve(4, points);
}

// 覆盖颜色
void Cover(float edge, float x, float y)
{
	setlinewidth(1);

	// 覆盖第二图层
	for (int i = 0; i < (int)(edge / 10.0); i++) {
		setcolor(EGEARGB(0xFF, 0x14, 0x14, 0x14));
		ege_line((edge / 7 * 2) + x, (edge / 1.20689655) + y + i, (edge / 7 * 5) + x, (edge / 1.20689655) + y + i);
		ege_line((edge / 7 * 2) + x, (edge / 1.2048192771) + y + i, (edge / 7 * 5) + x, (edge / 1.2048192771) + y + i);
		ege_line((edge / 7 * 2) + x, (edge / 1.2048192771) + y + i, (edge / 7 * 5) + x, (edge / 1.2048192771) + y + i);
		ege_line((edge / 6.73) + x - i, (edge / 1.42857) + y, (edge / 2.6415) + x, (edge / 1.208981) + y + i);
		ege_line((edge / 1.609) + x, (edge / 1.2048192771) + y + i, (edge / 1.17449664) + x + i, (edge / 1.42857) + y);
	}
	setfillcolor(EGERGB(20, 20, 20, 255));
	ege_fillellipse((edge / 7) + x, (edge / 7 / 2 * 10.9) + y, (edge / 7.7777778), (edge / 7.7777778));
	ege_fillellipse((edge / 7 * 5) + x, (edge / 1.3207547) + y, (edge / 7.7777778), (edge / 7.7777778));
}

// 打印字符
void character(float edge, float x, float y)
{
	// 打印字母设置
	setcolor(EGERGB(150, 150, 150, 255));
	setfont((edge / 7 / 4), 0, "等线", 0, 0, 1500, true, false, false);

	LOGFONTA f;
	getfont(&f);
	f.lfQuality = ANTIALIASED_QUALITY;
	setfont(&f);

	setbkmode(EGERGB(20, 20, 20, 255));
	outtextxy((edge / 2.544545) + x, (edge / 7 * 6.169584) + y, "BENDIX/KING");
}

// 最外侧框绘制
void Frames(float edge, float x, float y)
{
	setlinewidth(1);

	// 仪表外框
	for (int i = 0; i < (int)(edge / 60.0); i++) {
		setcolor(EGERGB(30 + 15 * i, 20 + 15 * i, 20 + 15 * i, 255));
		ege_line(x - i, y - i, x + edge + i, y - i);
		ege_line(x - i, y - i, x - i, y + edge + i);
		ege_line(x + edge + i, y - i, x + edge + i, y + edge + i);
		ege_line(x - i, y + edge + i, x + edge + i, y + edge + i);
	}
}

// 绘制旋转的线
void Revolve_line(float x1, float y1, float x2, float y2, float cx, float cy)
{
	setlinewidth(edge / 200.0);
	setcolor(EGERGB(170, 180, 200, 255));

	float newX1, newY1, newX2, newY2;
	float an = angle * 3.1414926 / 180.0;
	rotatePoint(x1, y1 + pitch, cx, cy, an, newX1, newY1);
	rotatePoint(x2, y2 + pitch, cx, cy, an, newX2, newY2);

	ege_line(newX1, newY1, newX2, newY2);
}

// 定义旋转函数
void rotatePoint(float x, float y, float centerX, float centerY, float an, float& x_new, float& y_new)
{
	x_new = centerX + (x - centerX) * cos(an) - (y - centerY) * sin(an);
	y_new = centerY + (x - centerX) * sin(an) + (y - centerY) * cos(an);
}